#!/sbin/openrc-run

description="Random number generator daemon"

pidfile="/run/$RC_SVCNAME.pid"
command="/usr/sbin/rngd"
command_args="-b -p $pidfile -D rngd:rngd"

depend() {
	after procfs urandom
	provide entropy
}

start_pre() {
	command_args="${command_args} ${EXTRA_ARGS}"

	for entsrc in ${INCLUDE_ENTROPY_SOURCES}; do
		command_args="${command_args} -n ${entsrc}"
	done

	for entsrc in ${EXCLUDE_ENTROPY_SOURCES}; do
		command_args="${command_args} -x ${entsrc}"
	done

	if [ "x${ENTROPY_COUNT}" != "x" ]; then
		command_args="${command_args} -e ${ENTROPY_COUNT}"
	fi

	if [ "x${FORCE_RESEED}" != "x" ]; then
		command_args="${command_args} -R ${FORCE_RESEED}"
	fi

	if [ "x${HWRNG_DEVICE}" != "x" ]; then
		command_args="${command_args} -r ${HWRNG_DEVICE}"
	fi

	if [ "x${RANDOM_DEVICE}" != "x" ]; then
		command_args="${command_args} -o ${RANDOM_DEVICE}"
	fi

	if [ "x${STEP}" != "x" ]; then
		command_args="${command_args} -s ${STEP}"
	fi

	if [ "x${WATERMARK}" != "x" ]; then
		command_args="${command_args} -W ${WATERMARK}"
	fi

	for entsrc_opt in ${DARN_OPTIONS}; do
		command_args="${command_args} -O darn:${entsrc_opt}"
	done

	for entsrc_opt in ${JITTER_OPTIONS}; do
		command_args="${command_args} -O jitter:${entsrc_opt}"
	done

	for entsrc_opt in ${RDRAND_OPTIONS}; do
		command_args="${command_args} -O rdrand:${entsrc_opt}"
	done

	for entsrc_opt in ${RNDR_OPTIONS}; do
		command_args="${command_args} -O rndr:${entsrc_opt}"
	done
}
